import axios from './axios'; // 确保导入的是封装后的 axios 实例


export const getAllArticles = async () => {
  try {
    const response = await axios.request({
      method: 'get',
      url: '/api/articles'
    });
    return response.data;
  } catch (error) {
    console.error('Error fetching articles:', error);
    throw error;
  }
};

export const getArticleById = async (id) => {
  try {
    const response = await axios.request({
      method: 'get',
      url: `/api/articles/${id}`
    });
    return response.data;
  } catch (error) {
    console.error(`Error fetching article with id ${id}:`, error);
    throw error;
  }
};